/**
 * 
 */
package soccerscope.view.layer;

import java.awt.Graphics;

import soccerscope.model.ClientScene;
import soccerscope.model.Param;
import soccerscope.model.Player;
import soccerscope.util.Color2;
import soccerscope.view.FieldPane;

/**
 * draws an arrow to the player we heared
 * 
 * @author wetzker
 * 
 */
public class HearLayer
    extends Layer {

  /**
   * @param fieldPane
   * @param enable
   */
  public HearLayer(
      FieldPane fieldPane,
      boolean enable) {

    super(fieldPane, enable);
  }

  /*
   * (non-Javadoc)
   * 
   * @see soccerscope.view.layer.Layer#getLayerName()
   */
  @Override
  public String getLayerName() {

    return "Hear";
  }

  @Override
  public void draw(Graphics g) {

    if (!this.enable) {
      return;
    }

    ClientScene clientScene = this.fieldPane.getScene();
    for (int i = 0; i < Param.MAX_PLAYER * 2; i++) {
      if (!clientScene.player[i].isEnable() || !this.fieldPane.isSelected(i)) {
        continue;
      }

      int mateNumber;
      Player p;
      Player mate;
      int index = -1;

      for (String s : clientScene.player[i].hearMessage) {
        if (s.length() == 0) {
          continue;
        }

        index = s.indexOf('-');
        if (index < 0) {
          continue;
        }

        mateNumber = Integer.parseInt(s.substring(0, index));
        if (mateNumber == 0) {
          continue;
        }
        p = clientScene.player[i];
        if (i > 10) {
          mateNumber += 11;
        }
        mate = clientScene.player[mateNumber - 1];
        g.setColor(Color2.red);
        this.drawArrow(g, p.pos, mate.pos);
      }
    }
  }

}
